package com

import org.apache.flink.api.scala._

/**
  * @Description: TODO QQ1667847363
  * @author: xiao kun tai
  * @date:2021/11/13 23:32
  *
  * 单词计数批处理
  */
object WordCount {
  def main(args: Array[String]): Unit = {

    //创建一个批处理的执行环境
    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment

    //从文件中读取数据
    val inputPath: String = "src/main/resources/hello.txt"
    val inputDataSet: DataSet[String] = env.readTextFile(inputPath)


    val resultDataSet: AggregateDataSet[(String, Int)] = inputDataSet
      .flatMap(_.split(" "))
      .map((_, 1))
      .groupBy(0)
      .sum(1)
    resultDataSet.print()


  }

}
